package com.booking.controller;

import com.booking.common.dto.ClientResp;
import com.booking.common.dto.PageReq;
import com.booking.common.dto.PageResp;
import com.booking.controller.model.req.homestay.HomestayCreateReq;
import com.booking.controller.model.req.homestay.HomestayQueryReq;
import com.booking.controller.model.req.homestay.HomestayRoomCreateReq;
import com.booking.controller.model.req.homestay.HomestayServiceCreateReq;
import com.booking.controller.model.res.HomestayDetail;
import com.booking.controller.model.res.HomestaySimpleInfo;
import com.booking.controller.model.res.RoomDetail;
import com.booking.controller.model.res.ServiceDetail;
import com.booking.service.HomestayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Qikai.Lin
 * @date 2023/4/23
 */
@Slf4j
@RestController
@RequestMapping("/api/homestay")
public class HomestayController {

    @Autowired
    private HomestayService homestayService;
    /* ----------------------民宿---------------------- */
    //查询民宿列表
    @PostMapping("/getAll")
    public ClientResp<PageResp<HomestaySimpleInfo>> getAllHomestay(@RequestBody @Valid PageReq<HomestayQueryReq> request) {
        return ClientResp.success(homestayService.getHomestaySimpleInfoPage(request));
    }
    //查询民宿详情
    @PostMapping("/getDetail")
    public ClientResp<HomestayDetail> getHomestayDetail(@RequestParam Long homestayId) {
        return ClientResp.success(homestayService.getHomestayDetail(homestayId));
    }
    //创建民宿
    @PostMapping("/create")
    public ClientResp<String> createHomestay(@RequestBody @Valid HomestayCreateReq request) {
        return ClientResp.success(homestayService.create(request));
    }
    //更新民宿
    @PostMapping("/update")
    public ClientResp<String> updateHomestay(@RequestBody @Valid HomestayCreateReq request) {
        return ClientResp.success();
    }
    //删除民宿
    @PostMapping("/delete")
    public ClientResp<String> deleteHomestay(@RequestParam Long homestayId) {
        homestayService.delete(homestayId);
        return ClientResp.success();
    }
    /* ----------------------房间---------------------- */
    //查询房间详情
    @PostMapping("/room/getDetail")
    public ClientResp<RoomDetail> getRoomDetail(@RequestParam Long roomId) {
        return ClientResp.success(homestayService.getRoomDetail(roomId));
    }
    //创建房间
    @PostMapping("/room/create")
    public ClientResp<String> createRoom(@RequestBody @Valid HomestayRoomCreateReq request) {
        return ClientResp.success(homestayService.createRoom(request));
    }
    //更新房间
    @PostMapping("/room/update")
    public ClientResp<String> updateRoom(@RequestBody @Valid HomestayRoomCreateReq request) {
        return ClientResp.success();
    }

    //删除房间
    @PostMapping("/room/delete")
    public ClientResp<String> deleteRoom(@RequestParam Long roomId) {
        homestayService.deleteRoom(roomId);
        return ClientResp.success();
    }

    /* ----------------------服务---------------------- */
    //查询服务详情
    @PostMapping("/service/getDetail")
    public ClientResp<ServiceDetail> getServiceDetail(@RequestParam Long serviceId) {
        return ClientResp.success(homestayService.getServiceDetail(serviceId));
    }
    //创建服务
    @PostMapping("/service/create")
    public ClientResp<String> createService(@RequestBody @Valid HomestayServiceCreateReq request) {
        return ClientResp.success(homestayService.createService(request));
    }
    //更新服务
    @PostMapping("/service/update")
    public ClientResp<String> updateService(@RequestBody @Valid HomestayServiceCreateReq request) {
        return ClientResp.success();
    }
    //删除服务
    @PostMapping("/service/delete")
    public ClientResp<String> deleteService(@RequestParam Long serviceId) {
        homestayService.deleteService(serviceId);
        return ClientResp.success();
    }

}
